package com.heima.greenScan.config;

import com.baidu.aip.contentcensor.AipContentCensor;

import com.heima.greenScan.properties.BaiduAiProperties;
import com.heima.greenScan.templete.BaiduAiTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

/**
 * @Author Administrator
 * @Date 2023/6/13
 **/
@EnableConfigurationProperties(BaiduAiProperties.class)
@ConditionalOnClass(AipContentCensor.class)
public class BaiduAiAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public AipContentCensor aipContentCensor(BaiduAiProperties baiduAiProperties) {
        // 初始化一个AipContentCensor
        AipContentCensor client = new AipContentCensor(baiduAiProperties.getAppId(), baiduAiProperties.getApiKey(), baiduAiProperties.getSecretKey());
        // 可选：设置网络连接参数
        client.setConnectionTimeoutInMillis(2000);
        client.setSocketTimeoutInMillis(60000);

        return client;
    }


    @Bean
    @ConditionalOnMissingBean
    public BaiduAiTemplate baiduAiTemplate(AipContentCensor aipContentCensor) {
        return new BaiduAiTemplate(aipContentCensor);
    }
}